package com.chunfen.dubbo.consumer;

import com.chunfen.dubbo.framework.Invocation;
import com.chunfen.dubbo.framework.ProxyFactory;
import com.chunfen.dubbo.protocol.http.HttpClient;
import com.chunfen.dubbo.provider.api.HelloService;
import com.chunfen.dubbo.util.GsonTool;
import com.google.gson.Gson;

import java.io.Serializable;
import java.lang.reflect.Proxy;
import java.util.Map;

public class Consumer {

    public static void main(String[] args) {

        //1 种  不用代理
//        HttpClient httpClient = new HttpClient();
//        Invocation invocation = new Invocation(HelloService.class.getName(), "hihi", new Class[]{String.class}, new String[]{"春分"});
//
//        Map<String, ? extends Serializable> result = httpClient.post("localhost", 8080, invocation);
//
//        System.out.println("收到数据啦" + GsonTool.toJsonString(result));

        //2 使用代理

        HelloService helloServiceProxy = (HelloService) ProxyFactory.getProxy(HelloService.class);

        System.out.println("收到数据啦" + GsonTool.toJsonString(helloServiceProxy.hihi("春分")));
    }
}
